#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2018 crane <crane@crane-pc>
#
# Distributed under terms of the MIT license.

import random
from  math import *


'''
    两人约会, 每个人在0-1小时之间到达概率相同.
    如果一个人到了, 另一个人15分钟内未到, 则离去!

    问: 两人约会成功概率?
'''


# results = []
total_cnt = 0
meet_cnt = 0


def one_meeting():
    global total_cnt, meet_cnt

    boy_arrive = random.random() * 60
    girl_arrive = random.random() * 60

    total_cnt += 1
    if fabs(boy_arrive - girl_arrive) <= 15:
        meet_cnt += 1


def statistic_result():
    pass

def meeting(n=10**6):
    global total_cnt, meet_cnt

    for i in range(n):
        one_meeting()

    print('meet success prob: [%s]' % (meet_cnt / total_cnt))
    print('理论成功率   prob: [%s]' % (7/16))


def main():
    print("start main")
    meeting()

if __name__ == "__main__":
    main()
